package br.com.ia.struts.action;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;

import br.com.enovar.trex.core.model.BaseModel;
import br.com.enovar.trex.struts.action.TRexCRUDBaseAction;
import br.com.enovar.trex.struts.form.TRexBaseForm;
import br.com.ia.model.Pergunta;
import br.com.ia.model.Variavel;
import br.com.ia.struts.form.PerguntaForm;
import br.com.ia.struts.form.VariavelForm;

public class PerguntaAction extends TRexCRUDBaseAction {

	@Override
	public BaseModel copyProperties(TRexBaseForm form) {
		Pergunta pergunta = new Pergunta();
		PerguntaForm perguntaForm = (PerguntaForm) form;
		VariavelForm variavelForm = perguntaForm.getVariavel();

		Variavel variavel = new Variavel();
		variavel.setCodigo(variavelForm.getCodigo());

		pergunta.setCodigo(perguntaForm.getCodigo());
		pergunta.setDescricao(perguntaForm.getDescricao());
		pergunta.setVariavel(variavel);

		return pergunta;
	}

	@Override
	public void copyProperties(BaseModel model, TRexBaseForm form) {
		
		PerguntaForm perguntaForm = (PerguntaForm)form;
		Pergunta pergunta = (Pergunta)model;
		Variavel variavel = pergunta.getVariavel();
		
		VariavelForm variavelForm = new VariavelForm();
		variavelForm.setCodigo(variavel.getCodigo());
		
		perguntaForm.setCodigo(pergunta.getCodigo());
		perguntaForm.setDescricao(pergunta.getDescricao());
		perguntaForm.setVariavel(variavelForm);

	}

	@Override
	public Serializable getId(TRexBaseForm form, HttpServletRequest request) {
		PerguntaForm perguntaForm = (PerguntaForm) form;
		return perguntaForm.getCodigo();
	}

}
